﻿using System;
using System.Collections.Generic;
using XRM.Security.DataAccess.Enums;
using XRM.Security.DataAccess.Helpers;
using XRM.Security.DataAccess.Interfaces;
using XRM.Security.WebUI.Models.Common;

namespace XRM.Security.WebUI.Models.CertRegister
{
    public class CertSearchItem : SearchItemBase, IUserCertStatus
    {
        public string SerialNumber { get; set; }
        public string SerialNumberEtoken { get; set; }
        public string IdentityCenterName { get; set; }
        public List<string> InfoSystems { get; set; }
        public string PCSerialNumber { get; set; }
        public DateTime FromDate { get; set; }
        public DateTime ToDate { get; set; }
        public int UserStatus { get; set; }
        
        public int? RequestId { get; set; }
        public int? RequestNumber { get; set; }

        private CertStatus? _status;
        public CertStatus Status 
        { 
            get
            {
                if (_status == null)
                {
                    _status = this.Status();
                }
                return _status.Value;
            } 
        }
        public string Period
        {
            get
            {
                return String.Format( "{0:dd.MM.yyyy} - {1:dd.MM.yyyy}", FromDate, ToDate );
            }
        }

        public string RowStyle
        {
            get
            {
                if ( Status == CertStatus.ExpireSoon )
                    return "warning";

                return Status == CertStatus.NotValid ? "inactive" : String.Empty;
            }
        }

        public string StatusIcon
        {
            get
            {
                if ( Status == CertStatus.ExpireSoon )
                    return "fa-exclamation-circle";

                return Status == CertStatus.NotValid ? "fa-times-circle" : "fa-check-circle";
            }
        }
    }
}